package com.pospi.pospihold.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pospi.pospihold.R;
import com.pospi.pospihold.dto.OrderBeen;
import com.pospi.pospihold.dto.OrderDto;
import com.pospi.pospihold.http.UploadData;
import com.pospi.pospihold.util.Constant;

import java.util.List;

/**
 * Created by Qiyan on 2016/6/21.
 */
public class RefundAdapter extends BaseAdapter {
    private Context context;
    private List<OrderBeen> orderDtos;

    public RefundAdapter(Context context, List<OrderBeen> orderDtos) {
        this.context = context;
        this.orderDtos = orderDtos;
    }

    @Override
    public int getCount() {
        return orderDtos.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDtos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.refund_item, null);
            holder = new Holder();
            holder.no = (TextView) convertView.findViewById(R.id.refund_xuliehao);
            holder.type = (TextView) convertView.findViewById(R.id.refund_type);
            holder.money = (TextView) convertView.findViewById(R.id.refund_money_ys);
            holder.time = (TextView) convertView.findViewById(R.id.refund_time_detail);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        OrderBeen dto = orderDtos.get(position);
        Log.i("小票号", "NO:" + String.valueOf(dto.getOrderNo()));
        holder.no.setText(String.valueOf(dto.getOrderNo()));
        holder.time.setText(dto.getDate());
        holder.money.setText(String.valueOf(dto.getAmount()));
        if (dto.getStutas().equals(UploadData.UP_SUCCESS)) {
            holder.type.setText("已上传");
        } else {
            holder.type.setText("未上传");
            holder.type.setTextColor(context.getResources().getColor(R.color.red));
        }
        return convertView;
    }

    class Holder {
        TextView no;
        TextView type;
        TextView time;
        TextView money;
    }
}
